package com.sxt.demo.djiapplication.dao;

import java.util.List;
import android.database.Cursor;
import android.database.sqlite.SQLiteStatement;

import org.greenrobot.greendao.AbstractDao;
import org.greenrobot.greendao.Property;
import org.greenrobot.greendao.internal.DaoConfig;
import org.greenrobot.greendao.database.Database;
import org.greenrobot.greendao.database.DatabaseStatement;
import org.greenrobot.greendao.query.Query;
import org.greenrobot.greendao.query.QueryBuilder;

import com.sxt.demo.djiapplication.entity.WayPointRecordItem;

// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/** 
 * DAO for table "way_point_record_list".
*/
public class WayPointRecordItemDao extends AbstractDao<WayPointRecordItem, Long> {

    public static final String TABLENAME = "way_point_record_list";

    /**
     * Properties of entity WayPointRecordItem.<br/>
     * Can be used for QueryBuilder and for referencing column names.
     */
    public static class Properties {
        public final static Property Id = new Property(0, Long.class, "id", true, "id");
        public final static Property Latitude = new Property(1, double.class, "latitude", false, "latitude");
        public final static Property Longitude = new Property(2, double.class, "longitude", false, "longitude");
        public final static Property Altitude = new Property(3, float.class, "altitude", false, "altitude");
        public final static Property Speed = new Property(4, float.class, "speed", false, "speed");
        public final static Property Order = new Property(5, int.class, "order", false, "order");
        public final static Property NeedTakePic = new Property(6, boolean.class, "needTakePic", false, "need_take_pic");
        public final static Property RecordId = new Property(7, Long.class, "recordId", false, "RECORD_ID");
    }

    private Query<WayPointRecordItem> wayPointRecord_WayPointRecordItemsQuery;

    public WayPointRecordItemDao(DaoConfig config) {
        super(config);
    }
    
    public WayPointRecordItemDao(DaoConfig config, DaoSession daoSession) {
        super(config, daoSession);
    }

    /** Creates the underlying database table. */
    public static void createTable(Database db, boolean ifNotExists) {
        String constraint = ifNotExists? "IF NOT EXISTS ": "";
        db.execSQL("CREATE TABLE " + constraint + "\"way_point_record_list\" (" + //
                "\"id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id
                "\"latitude\" REAL NOT NULL ," + // 1: latitude
                "\"longitude\" REAL NOT NULL ," + // 2: longitude
                "\"altitude\" REAL NOT NULL ," + // 3: altitude
                "\"speed\" REAL NOT NULL ," + // 4: speed
                "\"order\" INTEGER NOT NULL ," + // 5: order
                "\"need_take_pic\" INTEGER NOT NULL ," + // 6: needTakePic
                "\"RECORD_ID\" INTEGER);"); // 7: recordId
    }

    /** Drops the underlying database table. */
    public static void dropTable(Database db, boolean ifExists) {
        String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"way_point_record_list\"";
        db.execSQL(sql);
    }

    @Override
    protected final void bindValues(DatabaseStatement stmt, WayPointRecordItem entity) {
        stmt.clearBindings();
 
        Long id = entity.getId();
        if (id != null) {
            stmt.bindLong(1, id);
        }
        stmt.bindDouble(2, entity.getLatitude());
        stmt.bindDouble(3, entity.getLongitude());
        stmt.bindDouble(4, entity.getAltitude());
        stmt.bindDouble(5, entity.getSpeed());
        stmt.bindLong(6, entity.getOrder());
        stmt.bindLong(7, entity.getNeedTakePic() ? 1L: 0L);
 
        Long recordId = entity.getRecordId();
        if (recordId != null) {
            stmt.bindLong(8, recordId);
        }
    }

    @Override
    protected final void bindValues(SQLiteStatement stmt, WayPointRecordItem entity) {
        stmt.clearBindings();
 
        Long id = entity.getId();
        if (id != null) {
            stmt.bindLong(1, id);
        }
        stmt.bindDouble(2, entity.getLatitude());
        stmt.bindDouble(3, entity.getLongitude());
        stmt.bindDouble(4, entity.getAltitude());
        stmt.bindDouble(5, entity.getSpeed());
        stmt.bindLong(6, entity.getOrder());
        stmt.bindLong(7, entity.getNeedTakePic() ? 1L: 0L);
 
        Long recordId = entity.getRecordId();
        if (recordId != null) {
            stmt.bindLong(8, recordId);
        }
    }

    @Override
    public Long readKey(Cursor cursor, int offset) {
        return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0);
    }    

    @Override
    public WayPointRecordItem readEntity(Cursor cursor, int offset) {
        WayPointRecordItem entity = new WayPointRecordItem( //
            cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id
            cursor.getDouble(offset + 1), // latitude
            cursor.getDouble(offset + 2), // longitude
            cursor.getFloat(offset + 3), // altitude
            cursor.getFloat(offset + 4), // speed
            cursor.getInt(offset + 5), // order
            cursor.getShort(offset + 6) != 0, // needTakePic
            cursor.isNull(offset + 7) ? null : cursor.getLong(offset + 7) // recordId
        );
        return entity;
    }
     
    @Override
    public void readEntity(Cursor cursor, WayPointRecordItem entity, int offset) {
        entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0));
        entity.setLatitude(cursor.getDouble(offset + 1));
        entity.setLongitude(cursor.getDouble(offset + 2));
        entity.setAltitude(cursor.getFloat(offset + 3));
        entity.setSpeed(cursor.getFloat(offset + 4));
        entity.setOrder(cursor.getInt(offset + 5));
        entity.setNeedTakePic(cursor.getShort(offset + 6) != 0);
        entity.setRecordId(cursor.isNull(offset + 7) ? null : cursor.getLong(offset + 7));
     }
    
    @Override
    protected final Long updateKeyAfterInsert(WayPointRecordItem entity, long rowId) {
        entity.setId(rowId);
        return rowId;
    }
    
    @Override
    public Long getKey(WayPointRecordItem entity) {
        if(entity != null) {
            return entity.getId();
        } else {
            return null;
        }
    }

    @Override
    public boolean hasKey(WayPointRecordItem entity) {
        return entity.getId() != null;
    }

    @Override
    protected final boolean isEntityUpdateable() {
        return true;
    }
    
    /** Internal query to resolve the "wayPointRecordItems" to-many relationship of WayPointRecord. */
    public List<WayPointRecordItem> _queryWayPointRecord_WayPointRecordItems(Long recordId) {
        synchronized (this) {
            if (wayPointRecord_WayPointRecordItemsQuery == null) {
                QueryBuilder<WayPointRecordItem> queryBuilder = queryBuilder();
                queryBuilder.where(Properties.RecordId.eq(null));
                wayPointRecord_WayPointRecordItemsQuery = queryBuilder.build();
            }
        }
        Query<WayPointRecordItem> query = wayPointRecord_WayPointRecordItemsQuery.forCurrentThread();
        query.setParameter(0, recordId);
        return query.list();
    }

}
